package com.caration.shell.preference;

import android.content.Intent;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.PreferenceActivity;

import com.caration.shell.Home;
import com.caration.shell.R;
import com.caration.shell.config.CommonConfig;
import com.caration.shell.cr3d.SharedData;

public class SettingDrawerPreferenceActivity extends PreferenceActivity {

	private SeekBarPreference mRowsPref;
	private SeekBarPreference mColumnsPref;
	private SeekBarPreference mBackgroudAlphaPref;
	private boolean isAutoSize = false;

	public static void startup() {
		Intent intent = new Intent();
		intent.setClass(SharedData.getContext(),
				SettingDrawerPreferenceActivity.class);
		Home.getInstance().startActivity(intent);
	}

	private void saveCellCount() {
		int rows = mRowsPref.getProgress();
		int columns = mColumnsPref.getProgress();
		CommonConfig.setDrawerCellCount(rows, columns);
		// fm.h().k().b(rows, columns);
	}

	public void onCreate(Bundle paramBundle) {
		super.onCreate(paramBundle);
		addPreferencesFromResource(R.xml.preferences_drawer);
		isAutoSize = CommonConfig.isDrawerAutoSize();
		mRowsPref = ((SeekBarPreference) findPreference("rows"));
		mColumnsPref = ((SeekBarPreference) findPreference("columns"));
		mBackgroudAlphaPref = ((SeekBarPreference) findPreference("blackground_alpha"));
		mBackgroudAlphaPref.setMinSeek(0);
		mBackgroudAlphaPref.setMaxSeek(100);
		mBackgroudAlphaPref.setOppositeDependency(true);
		mBackgroudAlphaPref.setUnitsRight("%");
		// mRowsPref.setMinSeek(x.G);
		// mRowsPref.setMaxSeek(x.H);
		// mRowsPref.setOppositeDependency(true);
		// mColumnsPref.setOppositeDependency(true);
		// mColumnsPref.setMinSeek(x.I);
		// mColumnsPref.setMaxSeek(x.J);
		// mRowsPref.seek(x.A);
		// mColumnsPref.seek(x.B);
		// mBackgroudAlphaPref.seek(e.a);
		CheckBoxPreference localCheckBoxPreference = (CheckBoxPreference) findPreference("auto_size");
		localCheckBoxPreference.setChecked(isAutoSize);
		localCheckBoxPreference
				.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

					@Override
					public boolean onPreferenceChange(Preference preference,
							Object newValue) {
						isAutoSize = (Boolean) newValue;
						if (isAutoSize) {
							// mRowsPref.seek(x.K);
							// mColumnsPref.seek(x.L);
						}
						return true;
					}
				});
	}

	public void onPause() {
		int alpha = mBackgroudAlphaPref.getProgress();
		// if (alpha != e.a)
		// ShellConfig.setBackgourdAlpha(alpha);
		// if (!isAutoSize) {
		// if (ShellConfig.isDrawerAutoSize() != isAutoSize)
		// ShellConfig.setDrawerAutoSize(isAutoSize);
		// if (x.A == mRowsPref.getProgress()) {
		// if (x.B != mColumnsPref.getProgress())
		// saveCellCount();
		// } else
		// saveCellCount();
		// } else if (ShellConfig.isDrawerAutoSize() != isAutoSize) {
		// ShellConfig.setDrawerAutoSize(isAutoSize);
		// if ((x.A != mRowsPref.getProgress()) || (x.B !=
		// mColumnsPref.getProgress()))
		// fm.h().k().aR();
		// }
		super.onPause();
	}
}
